package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.VirtualWalletTransaction;
import com.neusoft.elmboot.service.VirtualWalletTransactionService;

@RestController
@RequestMapping("/VirtualWalletTransaction")
public class VirtualWalletTransactionController {
	@Autowired
	private VirtualWalletTransactionService transactionService;
	
	@GetMapping("/inquireTransaction")
    public List<VirtualWalletTransaction> listTransactionBywalletId(@RequestBody VirtualWalletTransaction virtualWalletTransaction){
    	return transactionService.listTransactionBywalletId(virtualWalletTransaction.getFromWalletId());
    }
	
	//取钱
	@PutMapping("/debit")
	public int decVirtualWallet(@RequestBody VirtualWalletTransaction virtualWalletTransaction) throws Exception{
		return transactionService.debit(virtualWalletTransaction);
	}
	
	//存钱
	@PutMapping("/credit")
	public int incVirtualWallet(@RequestBody VirtualWalletTransaction virtualWalletTransaction) throws Exception{
		return transactionService.crebit(virtualWalletTransaction);
	}
	
	//支付
	@PutMapping("/pay")
	public int VirtualWalletPay(@RequestBody VirtualWalletTransaction virtualWalletTransaction) throws Exception{
		return transactionService.pay(virtualWalletTransaction);
	}
	
	//冻结
	@PutMapping("/frozen")
	public int VirtualWalletFrozen(@RequestBody VirtualWalletTransaction virtualWalletTransaction) throws Exception{
		return transactionService.frozen(virtualWalletTransaction);
	}
	
	//解冻
	@PutMapping("/unfrozen")
	public int VirtualWalletUnfrozen(@RequestBody VirtualWalletTransaction virtualWalletTransaction) throws Exception{
		return transactionService.unfrozen(virtualWalletTransaction);
	}
	
	//支付透支额度
	@PutMapping("/payOverdraft")
	public int VirtualWalletpPayOverdraft(@RequestBody VirtualWalletTransaction virtualWalletTransaction) throws Exception{
		return transactionService.payOverdraft(virtualWalletTransaction);
	}
	
	//钱包中透支额收取利息
	public void checkOverdraft() {
		transactionService.checkOverdraft();
	}

}